package com.cn.controller.backstage;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.backstage.entity.member_entity;
import com.cn.controller.BaseServlet;
import com.cn.service.backstage_member_contlr;

@WebServlet("/backstage_member")
public class backstage_member extends BaseServlet{
	private backstage_member_contlr member;
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		member = new backstage_member_contlr();
		List<member_entity> list = member.getmember();
		req.setAttribute("list", list);
		forward("backstage_member");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		member = new backstage_member_contlr();
		//修改member
		String xg_phone=req.getParameter("phone_xg");
		if(xg_phone!=null&&xg_phone!=""){
			String xg_email=req.getParameter("email_xg");
			member.updatemember_email(xg_phone, xg_email);
		}
		//对余额进行修改
		String add_num=req.getParameter("num_num");
		String phone_jian=req.getParameter("phone_num_jian");
		String phone_jia=req.getParameter("phone_num_jia");
		String num_yue=req.getParameter("num_yue");
		if(add_num!=null&&add_num!=""&&phone_jian!=null&&phone_jian!=""){
			double num=Double.parseDouble(num_yue)-Double.parseDouble(add_num);
			member.updatemember_yue(phone_jian, num);
		}else if(add_num!=null&&add_num!=""&&phone_jia!=null&&phone_jia!=""){
			double num=Double.parseDouble(num_yue)+Double.parseDouble(add_num);
			member.updatemember_yue(phone_jia, num);
		}
		//对member进行删除
		String delete_phone=req.getParameter("delete_phone_");
		if(delete_phone!=null&&delete_phone!=""){
			member.deletemember(delete_phone);
		}
		//对member进行添加
		String phone_add=req.getParameter("phone_add");
		if(phone_add!=null&&phone_add!=""){
			String email_add=req.getParameter("email_add");
			String name_add=req.getParameter("name_add");
			member.addmember(name_add, phone_add, email_add);
		}
		//查询member
		String aname=req.getParameter("select_member");
		if(aname!=null&&aname!=""){
			List<member_entity> list = member.selectmember(aname);
			req.setAttribute("list", list);
		}else{
			List<member_entity> list = member.getmember();
			req.setAttribute("list", list);
		}
		forward("backstage_member");
	}
}
